home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / bin2arr.zip / SOURCE.ZIP / BIN2INC.CPP < prev   
C/C++ Source or Header  |  1994-12-27  |  4KB  |  164 lines

  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<io.h>
  5. #include<fcntl.h>
  6.  
  7. coolprintf(char *string,char FIRST_COLOR = 8,char SECOND_COLOR=7,char REST_COLOR=15)
  8. {
  9.       register int stringloop;
  10.       char first_letter;
  11.  
  12.  
  13.       textcolor(FIRST_COLOR);
  14.       cprintf("%c",string[0]);
  15.       textcolor(SECOND_COLOR);
  16.       cprintf("%c",string[1]);
  17.       textcolor(REST_COLOR);
  18.       stringloop=1;//2
  19.      while(string[stringloop++] != NULL)
  20.      {
  21.               if (first_letter==1)
  22.               {
  23.                      textcolor(FIRST_COLOR);
  24.                      cprintf("%c",string[stringloop]);
  25.                       textcolor(SECOND_COLOR);
  26.                       cprintf("%c",string[stringloop+1]);
  27.                       stringloop++;
  28.                       first_letter=0;
  29.                       textcolor(REST_COLOR);
  30.                }
  31.                else
  32.                cprintf("%c",string[stringloop]);
  33.                if (string[stringloop]==32) first_letter=1;
  34.        }
  35.  
  36. return 0;
  37. }
  38.  
  39.  
  40. char coolgets(char *string,char FIRST_COLOR = 2,char REST_COLOR=10)
  41. {
  42.       
  43.      unsigned char c;
  44.       int count=1;
  45.       string[0]=32;
  46.       char space_bar=0;
  47.  
  48.       while ((c = getch()) != 13 )
  49.       {
  50.               if(c==8)
  51.             {
  52.                    string[count-2]=32;
  53.                    if (count>1) cprintf("%c%c%c",8,32,8);
  54.                    else space_bar=0;
  55.                    count--;
  56.                    if (count<1) count =1;
  57.                     //if (string[count-2]==32) space_bar=0;
  58.                       if (string[count-2]==32) space_bar=0;
  59.                       if (count <1) if (string[count-2]==32) space_bar=0;
  60.                       else space_bar=1;
  61.               }
  62.  
  63.               if (c>32 && c<128 || c == 32)
  64.               {
  65.                      if (count <50)
  66.                      {
  67.                           count++;
  68.                           if (space_bar==0) {textcolor(FIRST_COLOR); space_bar=1;}
  69.                           else textcolor(REST_COLOR);
  70.                           if (c>32 && c<65) textcolor(REST_COLOR);
  71.                             if (c>47 && c<60) textcolor(FIRST_COLOR);
  72.  
  73.                           string[count-2]=c;
  74.                           cprintf("%c", c);
  75.                           space_bar=0;
  76.                            if (c==32) space_bar=0;
  77.                           else space_bar=1;
  78.                      }
  79.               }
  80.       }
  81.       printf("\n");
  82.       string[count-1]=NULL;
  83. return 0;
  84. }
  85.  
  86. main(int argc,unsigned char* argv[])
  87. {
  88.  
  89. if (argc<3)
  90.     {
  91.     printf("\n");
  92.     coolprintf("Usage:");
  93.     printf("\n");
  94.     
  95.     coolprintf("BIN2ASM [SOURCE BINARY] [OUTPUT ASM INCLUDE FILE]");
  96.     printf("\n");
  97.     
  98.     exit(1);
  99.     }
  100. unsigned char string[80];
  101. unsigned char buf[10];
  102. unsigned char array_name[80];
  103. unsigned long count,fl,count2=0,line=0;
  104.  
  105. int handle;
  106. FILE *fp;
  107.  
  108. if ((handle = open(argv[1], O_RDONLY | O_BINARY)) == -1)
  109. {
  110.     printf("\n");
  111.     sprintf(string,"Error: Cannot Open '%s'",argv[1]);
  112.     coolprintf(string);
  113.     printf("\n");
  114.     exit(1);
  115. }
  116.  
  117.  
  118. if((fp = fopen(argv[2], "w+")) ==NULL)
  119. {
  120.     printf("\n");
  121.     sprintf(string,"Error: Cannot Create '%s'",argv[2]);
  122.     coolprintf(string);
  123.     printf("\n");
  124.     exit(1);
  125. }
  126.  
  127. fl=filelength(handle);
  128.  
  129. printf("\n");
  130. coolprintf("Binary to ASM Array Converter By EMiNENT DOOM");
  131. printf("\n\n");
  132. coolprintf("Input Array Name:");
  133.  
  134. coolgets(array_name);
  135. printf("\r                      ");
  136.  
  137. fprintf(fp,"%s label byte \r\ndb ",array_name);
  138.  
  139. for(count=0;count<=fl;count++)
  140. {
  141. read(handle, buf, 1);
  142.  
  143.      if(count==fl) fprintf(fp,"%d",buf[0]);
  144.     else if(count2<=17) fprintf(fp,"%3d,",buf[0]);
  145.     else if(count2==18) fprintf(fp,"%3d",buf[0]);
  146.  
  147.  if(count2++ >=18) 
  148.     {
  149.     count2=0;
  150.     fprintf(fp,"\ndb ");
  151.     printf("\r");
  152.     sprintf(string,"Line: %d",line);
  153.     coolprintf(string);
  154.     line++;
  155.     }
  156. }
  157.  
  158. printf("\n");
  159. fclose(fp);
  160. close(handle);                    /* close the file */
  161.  
  162. return 0;
  163. }
  164.